package org.nekperu15739.jstl.controllers;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns={"/ajax"})
public class AjaxController extends HttpServlet {

	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String user = request.getParameter("user");
		request.setAttribute("user", user);
		RequestDispatcher dispatcher = request.getRequestDispatcher("ajax.jsp");
		dispatcher.forward(request, response);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		@SuppressWarnings("unused")
		Enumeration<String> parameterNames = request.getParameterNames();

		String user = request.getParameter("name");
		request.setAttribute("user", user);
		RequestDispatcher dispatcher = request.getRequestDispatcher("ajax.jsp");
		dispatcher.forward(request, response);
	}
	
}
